<!DOCTYPE html>
<html>
<head>
    <title>录入住院信息--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../../Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="../../Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="../../Css/style.css"/>
    <script type="text/javascript" src="../../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../../Js/ckform.js"></script>
    <script type="text/javascript" src="../../Js/common.js"></script>
    <script type="text/javascript" src="../../Js/ckeditor/ckeditor.js"></script>

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
        $(function () {
            $('#backid').click(function () {
                window.location.href = "index.html";
            });

            loadMsg();
        });

        String.prototype.GetValue = function (para) {
            let reg = new RegExp("(^|&)" + para + "=([^&]*)(&|$)");
            let r = this.substr(this.indexOf("\?") + 1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }

        // 获取挂号信息
        function loadMsg() {
            let url = document.location.toString();
            let behId = url.GetValue("behId");
            $("#behId").val(behId);

            $.ajax({
                url: `/be-hosipital/${behId}`,
                type: "GET",
                dataType: "json",
                success: function (res) {
                    if (res.code == 200) {
                        console.log(res)
                        let obj = res.obj;
                        $("#hosrId").html(obj.reg.hosrId);
                        $("#hosrName").html(obj.reg.hosrName);
                        $("#hosrIdcar").html(obj.reg.hosrIdcar);
                        $("#behAntecedent").html(obj.behAntecedent);
                    }
                }
            })
        }

        // 保存
        function save() {
            let behId = $("#behId").val();
            let behAntecedent = $("#behAntecedent").html();
            let money = $("input[name='money']").val();

            console.log(behId)
            console.log(behAntecedent)
            console.log(money)

            $.ajax({
                url: `/be-hosipital/save`,
                type: "POST",
                dataType: "json",
                data: {
                    behId, behAntecedent, money
                },
                success: function (res) {
                    alert(res.msg);
                    if (res.code === 200) {
                        // 跳转至查询页
                        $(location).attr("href", "index.html");
                    }
                }
            })
        }
    </script>
</head>
<body>
<form action="index.html" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <input type="hidden" id="behId" value="">
        <tr>
            <td width="10%" class="tableleft">病历号</td>
            <td id="hosrId">1103</td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">姓名</td>
            <td id="hosrName">黄飞鸿</td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">证件号</td>
            <td id="hosrIdcar">42068325467876</td>
        </tr>

        <tr>
            <td width="10%" class="tableleft">余额</td>
            <td id="behAntecedent">200</td>
        </tr>

        <tr>
            <td width="10%" class="tableleft">缴费押金</td>
            <td><input type="text" name="money" value="3000"/>&nbsp;元</td>
        </tr>

        <tr>
            <td colspan="2">
                <center>
                    <button onclick="save()" class="btn btn-primary" type="button">保存</button> &nbsp;&nbsp;<button
                        type="button" class="btn btn-success" name="backid" id="backid">返回列表
                </button>
                </center>
            </td>
        </tr>
    </table>
</form>
</body>
</html>